package com.luo.controller;

import com.alibaba.fastjson.JSON;
import com.luo.model.Goods;
import com.luo.model.Result;
import com.luo.service.GoodService;
import com.luo.util.ListTypes;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Random;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/1/9 19:58
 */
@WebServlet(urlPatterns = "/home/new")
public class NewGoodController extends HttpServlet {
    GoodService goodService = new GoodService();

    @Override
    protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        List<Goods> goods = goodService.queryNewGoods();
        Result result = new Result();
        result.setCode("1");
        result.setMsg("添加成功");
        result.setResult(ListTypes.getObjList(goods));
        String jsonString = JSON.toJSONString(result);
        resp.getWriter().write(jsonString);
        resp.getWriter().close();
    }
}
